package com.mjlf.mqserver.schedule;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mjlf.mqserver.entity.Topic;
import com.mjlf.mqserver.entity.TopicBluck;
import com.mjlf.restclient.entity.RestParams;
import com.mjlf.restclient.template.RestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @ClassName TopicsSchedule
 * @Author mjlft
 * @Date 2020/2/19 12:04
 * @Version 1.0
 * @Description TODO
 */
@Component
public class TopicsSchedule {
    @Autowired
    private RestTemplate restTemplate;

    @Value("${server.gettopic.path}")
    private String url;

    @Scheduled(cron = "${getTopic.corn}")
    public void getTopic() throws Exception {
        RestParams restParams = new RestParams();
        restParams.setUrl(url);
        TopicBluck.TOPIC = JSON.parseObject(restTemplate.get(restParams));
    }
}
